package com.wh.helloword;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: HuiEr
 * @Date: 2020/3/1 13:39
 * @Description
 */
public class TestCustomHashRealm {
    public static void main(String[] args) {
        Logger logger = LoggerFactory.getLogger(TestCustomHashRealm.class);
        IniSecurityManagerFactory securityManagerFactory = new IniSecurityManagerFactory("classpath:shiro-hash-realm.ini");
        SecurityManager securityManager = securityManagerFactory.getInstance();
        UsernamePasswordToken token = new UsernamePasswordToken("huihuier", "666");
        SecurityUtils.setSecurityManager(securityManager);
        Subject subject = SecurityUtils.getSubject();
        subject.login(token);
        logger.info(""+subject.isAuthenticated());

        boolean permitted = subject.isPermitted("user:add");
        System.out.println(permitted);

        /*boolean[] permitted1 = subject.isPermitted("", "");
        System.out.println(permitted1);*/

        subject.hasAllRoles(new ArrayList<String>());

    }
}
